﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace KXmlUIControl
{
    /// <summary>
    /// XML图像对象类
    /// </summary>
    public class XmlImageObject
    {       
        /// <summary>
        /// 在程序中引用其的对象名称
        /// </summary>
        public string Name {get; set;}        
    
        /// <summary>
        /// 本地加载的文件名称
        /// </summary>
        public string FileName
        {
            get
            {
                if (string.IsNullOrEmpty(ImagePath))
                {
                    return "";
                }
                return Path.Combine(StaticTypes.ImageFolder, ImagePath);
            }
        }

        /// <summary>
        /// 配置文件中配置的相对路径
        /// </summary>
        public string ImagePath { get; set; }

        public XmlImageObject()
        {
            
        }

        public Image GetImage()
        {
            if (File.Exists(FileName))
            {
                try
                {
                    Image image = Image.FromFile(FileName);
                    if (image != null)
                    {
                        image.Tag = Name;
                    }
                    return image;
                }
                catch
                {
                    return null;
                }
            }
            return null;
        }
    }
}
